home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / batcsh10.zip / lexyy.c < prev    next >
C/C++ Source or Header  |  1994-01-12  |  47KB  |  1,809 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. /* scanner skeleton version:
  4.  * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
  5.  */
  6.  
  7. #define FLEX_SCANNER
  8.  
  9. #include <stdio.h>
  10.  
  11.  
  12. /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  13. #ifdef c_plusplus
  14. #ifndef __cplusplus
  15. #define __cplusplus
  16. #endif
  17. #endif
  18.  
  19.  
  20. #ifdef __cplusplus
  21.  
  22. #include <stdlib.h>
  23. #include <osfcn.h>
  24.  
  25. /* use prototypes in function declarations */
  26. #define YY_USE_PROTOS
  27.  
  28. /* the "const" storage-class-modifier is valid */
  29. #define YY_USE_CONST
  30.  
  31. #else    /* ! __cplusplus */
  32.  
  33. #ifdef __STDC__
  34.  
  35. #ifdef __GNUC__
  36. #include <stddef.h>
  37. void *malloc( size_t );
  38. void free( void* );
  39. #else
  40. #include <stdlib.h>
  41. #endif    /* __GNUC__ */
  42.  
  43. #define YY_USE_PROTOS
  44. #define YY_USE_CONST
  45.  
  46. #endif    /* __STDC__ */
  47. #endif    /* ! __cplusplus */
  48.  
  49.  
  50. #ifdef __TURBOC__
  51. #define YY_USE_PROTOS
  52. #define YY_USE_CONST
  53. #endif
  54.  
  55.  
  56. #ifndef YY_USE_CONST
  57. #define const
  58. #endif
  59.  
  60.  
  61. #ifdef YY_USE_PROTOS
  62. #define YY_PROTO(proto) proto
  63. #else
  64. #define YY_PROTO(proto) ()
  65.  
  66. #ifdef __TURBOC__
  67. #include <alloc.h>
  68. #include <io.h>
  69. #else
  70. /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
  71.  * so it's got to be a K&R compiler, and therefore there's no standard
  72.  * place from which to include these definitions
  73.  */
  74. char *malloc();
  75. int free();
  76. int read();
  77. #endif
  78. #endif
  79.  
  80.  
  81. /* amount of stuff to slurp up with each read */
  82. #ifndef YY_READ_BUF_SIZE
  83. #define YY_READ_BUF_SIZE 8192
  84. #endif
  85.  
  86. /* returned upon end-of-file */
  87. #define YY_END_TOK 0
  88.  
  89. /* copy whatever the last rule matched to the standard output */
  90.  
  91. /* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
  92. /* this used to be an fputs(), but since the string might contain NUL's,
  93.  * we now use fwrite()
  94.  */
  95. #define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
  96.  
  97. /* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  98.  * is returned in "result".
  99.  */
  100. #define YY_INPUT(buf,result,max_size) \
  101.     if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
  102.         YY_FATAL_ERROR( "read() in flex scanner failed" );
  103. #define YY_NULL 0
  104.  
  105. /* no semi-colon after return; correct usage is to write "yyterminate();" -
  106.  * we don't want an extra ';' after the "return" because that will cause
  107.  * some compilers to complain about unreachable statements.
  108.  */
  109. #define yyterminate() return ( YY_NULL )
  110.  
  111. /* report a fatal error */
  112.  
  113. /* The funky do-while is used to turn this macro definition into
  114.  * a single C statement (which needs a semi-colon terminator).
  115.  * This avoids problems with code like:
  116.  *
  117.  *     if ( something_happens )
  118.  *        YY_FATAL_ERROR( "oops, the something happened" );
  119.  *    else
  120.  *        everything_okay();
  121.  *
  122.  * Prior to using the do-while the compiler would get upset at the
  123.  * "else" because it interpreted the "if" statement as being all
  124.  * done when it reached the ';' after the YY_FATAL_ERROR() call.
  125.  */
  126.  
  127. #define YY_FATAL_ERROR(msg) \
  128.     do \
  129.         { \
  130.         (void) fputs( msg, stderr ); \
  131.         (void) putc( '\n', stderr ); \
  132.         exit( 1 ); \
  133.         } \
  134.     while ( 0 )
  135.  
  136. /* default yywrap function - always treat EOF as an EOF */
  137. #define yywrap() 1
  138.  
  139. /* enter a start condition.  This macro really ought to take a parameter,
  140.  * but we do it the disgusting crufty way forced on us by the ()-less
  141.  * definition of BEGIN
  142.  */
  143. #define BEGIN yy_start = 1 + 2 *
  144.  
  145. /* action number for EOF rule of a given start state */
  146. #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  147.  
  148. /* special action meaning "start processing a new file" */
  149. #define YY_NEW_FILE \
  150.     do \
  151.         { \
  152.         yy_init_buffer( yy_current_buffer, yyin ); \
  153.         yy_load_buffer_state(); \
  154.         } \
  155.     while ( 0 )
  156.  
  157. /* default declaration of generated scanner - a define so the user can
  158.  * easily add parameters
  159.  */
  160. #define YY_DECL int yylex YY_PROTO(( void )) 
  161.  
  162. /* code executed at the end of each rule */
  163. #define YY_BREAK break;
  164.  
  165. #define YY_END_OF_BUFFER_CHAR 0
  166.  
  167. #ifndef YY_BUF_SIZE
  168. #define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
  169. #endif
  170.  
  171. typedef struct yy_buffer_state *YY_BUFFER_STATE;
  172.  
  173. #define YY_CHAR char
  174. #define INITIAL 0
  175. /**************************************************************************/
  176. /*    MODULE: bat2csh.l                                                   */
  177. /*   PURPOSE: converts dos batch files to unix csh files                  */
  178. /*    AUTHOR: Bill Pierpoint                                              */
  179. /*       LEX: FLEX Version 2.3.7                                          */
  180. /*  COMPILER: Borland C Version 3.1                                       */
  181. /* COPYRIGHT: None.  Public Domain.                                       */
  182. /*   VERSION: 1.00                                                        */
  183. /*   RELEASE: January 12, 1994                                            */
  184. /**************************************************************************/
  185. #include <stdc.h>
  186. #ifdef __BORLANDC__
  187. #pragma hdrstop
  188. #endif
  189.  
  190. #define putstr(s)    fputs((s),  stdout)
  191. #define puttab()    fputc('\t', stdout)
  192. #define putln()        fputc('\n', stdout)
  193. #define token(t)    (t)
  194. #define ckeol(t)    do { if((t)==EOL) { puts(" ### SYNTAX ERROR ###"); \
  195.                           errorcount++; return;} } while(0)
  196. #define cktok(t, x)    do { if((t)!=(x)) { puts(" ### SYNTAX ERROR ###"); \
  197.                           errorcount++; eattokens(); return;} } while(0)
  198.  
  199. typedef struct
  200. {
  201.     int token;
  202.     void (*fn)(void);
  203. } FNTBL;
  204.  
  205. #define STRBUFSIZE    129
  206. char textbuf[STRBUFSIZE];
  207.  
  208. /**************************************************************************/
  209. /* token enumeration                                                      */
  210. /**************************************************************************/
  211. enum {
  212.     OTHER=1,
  213.     EOL,
  214.     SPACE,
  215.     VARIABLE,
  216.     PARAMETER,
  217.     WORD,
  218.     INIT_CALL,
  219.     INIT_ECHO,
  220.     INIT_FOR,
  221.     INIT_GOTO,
  222.     INIT_IF,
  223.     INIT_PATH,
  224.     INIT_PAUSE,
  225.     INIT_REM,
  226.     INIT_SET,
  227.     INIT_SHIFT,
  228.     INIT_LABEL,
  229.     INIT_COMMAND,
  230.     ECHO_ON,
  231.     ECHO_OFF,
  232.     ECHO_DOT,
  233.     IF_NOT,
  234.     IF_ERRORLEVEL,
  235.     IF_EXIST,
  236.     FOR_VARIABLE,
  237.     FOR_IN,
  238.     FOR_WORDLIST,
  239.     FOR_DO
  240. };
  241.  
  242. /**************************************************************************/
  243. /* function prototypes                                                    */
  244. /**************************************************************************/
  245. /* support functions */
  246. char *cvt_parameter(char *s);
  247. char *cvt_variable(char *s);
  248. char *cvt_for_variable(char *s);
  249. char *cvt_set_variable(int token);
  250. char *cvt_token(int token, char *s);
  251. int dispatch(void);
  252. void indent(void);
  253. int lex(void);
  254. void putbacktoken(void);
  255. void puttokln(int token, char *start, char *end);
  256. int  reporterrors(void);
  257. void terminate(void);
  258. char *tr(char *s, int oldch, int newch);
  259.  
  260. /* keyword functions */
  261. void kw_call(void);
  262. void kw_command(void);
  263. void kw_echo(void);
  264. void kw_for(void);
  265. void kw_goto(void);
  266. void kw_if(void);
  267. void kw_label(void);
  268. void kw_ln(void);
  269. void kw_path(void);
  270. void kw_pause(void);
  271. void kw_remark(void);
  272. void kw_set(void);
  273. void kw_shift(void);
  274.  
  275. #define ECHOS 1
  276. #define TEXT 2
  277. #define FOR 3
  278.  
  279. /* done after the current pattern has been matched and before the
  280.  * corresponding action - sets up yytext
  281.  */
  282. #define YY_DO_BEFORE_ACTION \
  283.     yytext = yy_bp; \
  284.     yyleng = yy_cp - yy_bp; \
  285.     yy_hold_char = *yy_cp; \
  286.     *yy_cp = '\0'; \
  287.     yy_c_buf_p = yy_cp;
  288.  
  289. #define EOB_ACT_CONTINUE_SCAN 0
  290. #define EOB_ACT_END_OF_FILE 1
  291. #define EOB_ACT_LAST_MATCH 2
  292.  
  293. /* return all but the first 'n' matched characters back to the input stream */
  294. #define yyless(n) \
  295.     do \
  296.         { \
  297.         /* undo effects of setting up yytext */ \
  298.         *yy_cp = yy_hold_char; \
  299.         yy_c_buf_p = yy_cp = yy_bp + n; \
  300.         YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  301.         } \
  302.     while ( 0 )
  303.  
  304. #define unput(c) yyunput( c, yytext )
  305.  
  306.  
  307. struct yy_buffer_state
  308.     {
  309.     FILE *yy_input_file;
  310.  
  311.     YY_CHAR *yy_ch_buf;        /* input buffer */
  312.     YY_CHAR *yy_buf_pos;    /* current position in input buffer */
  313.  
  314.     /* size of input buffer in bytes, not including room for EOB characters*/
  315.     int yy_buf_size;    
  316.  
  317.     /* number of ch